package com.huabo.contract.oracle.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hbfk.util.PageInfo;
import com.huabo.contract.oracle.entity.TblContractProject;
import com.huabo.contract.oracle.vo.TblContractProjectVo;

public interface TblContractProjectMapper extends BaseMapper<TblContractProject>{
	@Select("SELECT * from TBL_CONTRACT_PROJECT WHERE PROJECTID= #{projectid} ")
    TblContractProject getById(String projectid);
    
    @SelectProvider(method="selectCountByPageInfo",type=TblContractProjectMapperSqlConfig.class)
   	Integer selectCountByPageInfo(PageInfo<TblContractProject> pageInfo,TblContractProjectVo tblContractProjectVo,Integer staffid) throws Exception;

    @Select("SELECT TNA.*,STAFF.REALNAME,ORG.ORGNAME "
    		+ "FROM TBL_CONTRACT_PROJECT TNA "
    		+ "LEFT JOIN TBL_STAFF STAFF ON STAFF.STAFFID = TNA.UNDERTAKESTAFFID "
			+ "LEFT JOIN TBL_ORGANIZATION ORG ON ORG.ORGID = TNA.UNDERTAKEORGID "
    		+ " WHERE TNA.PROJECTID = #{projectid}")
    @Results({
    	@Result(column="PROJECTID",property="projectid"),
    	@Result(column="PROJECTNAME",property="projectname"),
    	@Result(column="PROJECTCODE",property="projectcode"),
    	@Result(column="MEMO",property="memo"),
    	
    	@Result(column="REALNAME",property="undertakestaff.realname"),
    	@Result(column="ORGNAME",property="undertakeorg.orgname"),
    })
   	TblContractProject selectById(@Param("projectid") Integer projectid) throws Exception;
    
    @SelectProvider(method="selectListByPageInfo",type=TblContractProjectMapperSqlConfig.class)
    @Results({
    	@Result(column="PROJECTID",property="projectid"),
    	@Result(column="PROJECTNAME",property="projectname"),
    	@Result(column="PROJECTCODE",property="projectcode"),
    	@Result(column="MEMO",property="memo"),
    	
    	@Result(column="REALNAME",property="undertakestaff.realname"),
    	@Result(column="ORGNAME",property="undertakeorg.orgname"),
    })
	List<TblContractProject> selectListByPageInfo(PageInfo<TblContractProject> pageInfo,TblContractProjectVo tblContractProjectVo,Integer staffid) throws Exception;

    @Delete("DELETE FROM TBL_CONTRACT_PROJECT WHERE PROJECTID = #{projectid}")
    void deleteById(Integer projectid) throws Exception;

    @SelectProvider(method="selectPlanCodeByOrgid",type=TblContractProjectMapperSqlConfig.class)
	Integer selectPlanCodeByOrgid(TblContractProject plan) throws Exception;
    
    @InsertProvider(method="insertEntity",type=TblContractProjectMapperSqlConfig.class)
    @Options(useGeneratedKeys=true, keyProperty="projectid", keyColumn="PROJECTID")
	void insertEntity(TblContractProject plan) throws Exception;

    @UpdateProvider(method="updateEntity",type=TblContractProjectMapperSqlConfig.class)
	void updateEntity(TblContractProject plan) throws Exception;

    @Delete("DELETE FROM TBL_LEGAL_CONTRACT_PROJECT_ATT WHERE PROJECTID = #{projectid}")
	void deleteFileRelation(Integer projectid);

    @Delete("DELETE FROM TBL_LEGAL_CONTRACT_PROJECT_ATT WHERE ATTID = #{attId}")
	void deleteFileId(String attId);
}
